import tkinter as tk
from tkinter import messagebox
import time

class ExamApp:
    def __init__(self, root):
        self.root = root
        self.root.title("Exam Platform")

        self.time_limit = 60  # Time limit in seconds
        self.time_remaining = self.time_limit

        # Create and place widgets
        self.question_label = tk.Label(root, text="Question 1: What is 2 + 2?")
        self.question_label.pack()

        self.option_var = tk.StringVar(value="")

        self.option_a = tk.Radiobutton(root, text="3", variable=self.option_var, value="A")
        self.option_b = tk.Radiobutton(root, text="4", variable=self.option_var, value="B")
        self.option_a.pack()
        self.option_b.pack()

        self.submit_button = tk.Button(root, text="Submit", command=self.submit_answer)
        self.submit_button.pack()

        self.timer_label = tk.Label(root, text="Time left: {} seconds".format(self.time_limit))
        self.timer_label.pack()

        self.start_timer()

    def start_timer(self):
        self.update_timer()
        self.root.after(1000, self.countdown)

    def countdown(self):
        if self.time_remaining > 0:
            self.time_remaining -= 1
            self.update_timer()
            self.root.after(1000, self.countdown)
        else:
            messagebox.showinfo("Time's Up", "Time is up! Your answers have been submitted.")
            self.submit_answer()

    def update_timer(self):
        self.timer_label.config(text="Time left: {} seconds".format(self.time_remaining))

    def submit_answer(self):
        # Handle the answer submission logic
        selected_option = self.option_var.get()
        if selected_option:
            messagebox.showinfo("Answer Submitted", f"Your selected option is {selected_option}")
        else:
            messagebox.showinfo("Answer Submitted", "No option selected")

        self.root.quit()

if __name__ == "__main__":
    root = tk.Tk()
    app = ExamApp(root)
    root.mainloop()